package com.dream.essearch.controller;

import com.dream.essearch.model.dto.BookDTO;
import com.dream.essearch.model.dto.SearchParam;
import com.dream.essearch.service.IBookService;
import com.dream.essearch.wrap.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 图书controller
 * @author: LiMG
 * @create: 2025-04-28 01:00:16
 **/
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private IBookService bookService;

    @GetMapping("/getList")
    private R getList() {
        return R.ok().setData(bookService.getBookList());
    }

    @PostMapping("/saveBook")
    private R saveBook(@RequestBody BookDTO bookDTO) {
        bookService.saveBook(bookDTO);
        return R.ok();
    }

    @GetMapping("/getSuggest")
    private R getSuggest(@RequestParam("keyword") String keyword) {
        return R.ok().setData(bookService.getSuggest(keyword));
    }

    @PostMapping("/search")
    private R search(@RequestBody SearchParam param) {
        return R.ok().setData(bookService.search(param));
    }

}
